<!DOCTYPE html><html><head><title>README</title><link href="http://www.jboss.org/jdf/stylesheets/documentation.css" rel="stylesheet"></link><link href="http://www.jboss.org/jdf/stylesheets/pygments.css" rel="stylesheet"></link></head><body>
<h1><a id="ejbasynchronous-an-application-with-an-ejb-with-asynchronous-methods-to-demonstrate-how-it-works" class="anchor" href="#ejbasynchronous-an-application-with-an-ejb-with-asynchronous-methods-to-demonstrate-how-it-works"><span class="anchor-icon"></span></a>ejb-asynchronous:  An application with an EJB with asynchronous methods to demonstrate how it works</h1>

<p>Author: Wolf-Dieter Fink<br/>
Level: Advanced<br/>
Technologies: EJB<br/>
Summary: Demonstrates asynchronous EJB invocations.<br/>
Target Product: EAP<br/>
Product Versions: EAP 6.1, EAP 6.2<br/>
Source: <a href="https://github.com/jboss-developer/jboss-eap-quickstarts/">https://github.com/jboss-developer/jboss-eap-quickstarts/</a>  </p>

<h2><a id="what-is-it" class="anchor" href="#what-is-it"><span class="anchor-icon"></span></a>What is it?</h2>

<p>This is a quickstart to demonstrate the behavior of asynchronous EJB invocations. The methods are invoked by both an EJB in the deployment and by a remote client. The quickstart also shows error handling if the asynchronous method invocation fails.</p>

<p>The example is composed of 2 maven modules, each with a shared parent. The modules are as follows:</p>

<ol>
<li><code>ejb</code>: This module contains the EJB&rsquo;s and will be deployed to the server</li>
<li><code>client</code> : This module contains a remote ejb client</li>
</ol>

<p>The root <code>pom.xml</code> builds each of the submodules in the above order and deploys the archive to the server.</p>

<h2><a id="system-requirements" class="anchor" href="#system-requirements"><span class="anchor-icon"></span></a>System requirements</h2>

<p>The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 6.1 or later. </p>

<p>All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later.</p>

<h2><a id="configure-maven" class="anchor" href="#configure-maven"><span class="anchor-icon"></span></a>Configure Maven</h2>

<p>You can copy or link to the Maven configuration information in the README file in the root folder of the quickstarts. For example:</p>

<p>If you have not yet done so, you must <a href="../README.html#configure-maven">Configure Maven</a> before testing the quickstarts.</p>

<h2><a id="start-the-jboss-server" class="anchor" href="#start-the-jboss-server"><span class="anchor-icon"></span></a>Start the JBoss Server</h2>

<ol>
<li>Open a command line and navigate to the root of the JBoss server directory.</li>
<li><p>The following shows the command line to start the server:</p>
<div class="highlight"><pre> <span class="n">For</span> <span class="n">Linux</span><span class="o">:</span>   <span class="n">JBOSS_HOME</span><span class="o">/</span><span class="n">bin</span><span class="o">/</span><span class="n">standalone</span><span class="p">.</span><span class="n">sh</span>
 <span class="n">For</span> <span class="n">Windows</span><span class="o">:</span> <span class="n">JBOSS_HOME</span><span class="err">\</span><span class="n">bin</span><span class="err">\</span><span class="n">standalone</span><span class="p">.</span><span class="n">bat</span>
</pre></div></li>
</ol>

<h2><a id="build-and-deploy-the-quickstart" class="anchor" href="#build-and-deploy-the-quickstart"><span class="anchor-icon"></span></a>Build and Deploy the Quickstart</h2>

<p><em>NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See <a href="../README.html#build-and-deploy-the-quickstarts">Build and Deploy the Quickstarts</a> for complete instructions and additional options.</em></p>

<ol>
<li>Make sure you have started the JBoss Server as described above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>Type this command to build and deploy the archive:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">clean</span> <span class="n">install</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="o">:</span><span class="n">deploy</span>
</pre></div></li>
<li><p>This will deploy <code>service/target/jboss-ejb-asynchronous.jar</code> to the running instance of the server.</p></li>
</ol>

<p>Check whether the application is deployed successfully.</p>

<h2><a id="access-the-application" class="anchor" href="#access-the-application"><span class="anchor-icon"></span></a>Access the application</h2>

<ol>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>Type this command to start the client</p>
<div class="highlight"><pre><span class="n">cd</span> <span class="n">client</span>
<span class="n">mvn</span> <span class="n">exec</span><span class="o">:</span><span class="n">exec</span>
</pre></div></li>
<li><p>Check the client output</p>
<div class="highlight"><pre><span class="n">INFO</span><span class="o">:</span> <span class="n">The</span> <span class="n">server</span> <span class="n">log</span> <span class="n">should</span> <span class="n">contain</span> <span class="n">a</span> <span class="n">message</span> <span class="n">at</span> <span class="o">(</span><span class="n">about</span><span class="o">)</span> <span class="o">&lt;</span><span class="n">date</span><span class="o">&gt;,</span> <span class="n">indicating</span> <span class="n">that</span> <span class="n">the</span> <span class="n">call</span> <span class="n">to</span> <span class="n">the</span> <span class="n">asynchronous</span> <span class="n">bean</span> <span class="n">completed</span><span class="o">.</span>
<span class="n">INFO</span><span class="o">:</span> <span class="n">Got</span> <span class="n">the</span> <span class="n">async</span> <span class="n">result</span> <span class="k">as</span> <span class="n">expected</span> <span class="o">=&gt;</span> <span class="n">returning</span> <span class="n">at</span> <span class="o">&lt;</span><span class="n">date</span><span class="o">&gt;,</span> <span class="n">duration</span> <span class="n">was</span> <span class="mi">200</span><span class="n">ms</span>
<span class="n">INFO</span><span class="o">:</span> <span class="n">Got</span> <span class="n">the</span> <span class="n">async</span> <span class="n">result</span> <span class="k">as</span> <span class="n">expected</span> <span class="n">after</span> <span class="n">wait</span> <span class="o">=&gt;</span> <span class="n">returning</span> <span class="n">at</span> <span class="o">&lt;</span><span class="n">date</span><span class="o">&gt;,</span> <span class="n">duration</span> <span class="n">was</span> <span class="mi">1500</span><span class="n">ms</span>
<span class="n">INFO</span><span class="o">:</span> <span class="n">Catch</span> <span class="n">the</span> <span class="n">expected</span> <span class="n">Exception</span> <span class="n">of</span> <span class="n">the</span> <span class="n">asynchronous</span> <span class="n">execution</span><span class="o">!</span>
<span class="n">INFO</span><span class="o">:</span> <span class="n">Results</span> <span class="n">of</span> <span class="n">the</span> <span class="n">parallel</span> <span class="o">(</span><span class="n">server</span><span class="o">)</span> <span class="n">processing</span> <span class="o">:</span> <span class="o">[</span><span class="n">returning</span> <span class="n">at</span> <span class="o">&lt;</span><span class="n">date</span><span class="o">&gt;</span> <span class="n">duration</span> <span class="n">was</span> <span class="mi">5000</span><span class="n">ms</span><span class="o">,</span> <span class="n">returning</span> <span class="n">at</span> <span class="o">&lt;</span><span class="n">date</span><span class="o">&gt;,</span> <span class="n">duration</span> <span class="n">was</span> <span class="mi">3000</span><span class="n">ms</span><span class="o">]</span>
</pre></div></li>
<li><p>Check the server log. </p>

<p>There should be two INFO log messages for the <code>fireAndForget</code> invocation:</p>
<div class="highlight"><pre>  <span class="err">&#39;</span><span class="n">fireAndForget</span><span class="err">&#39;</span> <span class="n">Will</span> <span class="n">wait</span> <span class="k">for</span> <span class="mi">15000</span><span class="n">ms</span>
</pre></div>
<p>and 15sec later (the client should be finished at this time)</p>
<div class="highlight"><pre>  <span class="n">action</span> <span class="err">&#39;</span><span class="n">fireAndForget</span><span class="err">&#39;</span> <span class="n">finished</span>
</pre></div></li>
</ol>

<p><em>NOTE: In EAP 6.2, you may see the following errors in the server log after the client tests successfully complete. This is due to an issue with the server opening the outputstream and you can ignore the errors.</em></p>
<div class="highlight"><pre>    <span class="nl">JBAS014249:</span> <span class="n">Error</span> <span class="n">invoking</span> <span class="n">method</span> <span class="n">public</span> <span class="n">abstract</span> <span class="kt">void</span> <span class="n">org</span><span class="p">.</span><span class="n">jboss</span><span class="p">.</span><span class="n">as</span><span class="p">.</span><span class="n">quickstarts</span><span class="p">.</span><span class="n">ejb</span><span class="p">.</span><span class="n">asynchronous</span><span class="p">.</span><span class="n">AsynchronousAccess</span><span class="p">.</span><span class="n">fireAndForget</span><span class="p">(</span><span class="kt">long</span><span class="p">)</span> <span class="n">on</span> <span class="n">bean</span> <span class="n">named</span> <span class="n">AsynchronousAccessBean</span> <span class="k">for</span> <span class="n">appname</span>  <span class="n">modulename</span> <span class="n">jboss</span><span class="o">-</span><span class="n">ejb</span><span class="o">-</span><span class="n">asynchronous</span><span class="o">-</span><span class="n">ejb</span> <span class="n">distinctname</span> <span class="o">:</span> <span class="n">java</span><span class="p">.</span><span class="n">lang</span><span class="p">.</span><span class="n">NullPointerException</span>

    <span class="nl">JBAS014250:</span> <span class="n">Could</span> <span class="n">not</span> <span class="n">write</span> <span class="n">method</span> <span class="n">invocation</span> <span class="n">failure</span> <span class="k">for</span> <span class="n">method</span> <span class="n">public</span> <span class="n">abstract</span> <span class="kt">void</span> <span class="n">org</span><span class="p">.</span><span class="n">jboss</span><span class="p">.</span><span class="n">as</span><span class="p">.</span><span class="n">quickstarts</span><span class="p">.</span><span class="n">ejb</span><span class="p">.</span><span class="n">asynchronous</span><span class="p">.</span><span class="n">AsynchronousAccess</span><span class="p">.</span><span class="n">fireAndForget</span><span class="p">(</span><span class="kt">long</span><span class="p">)</span> <span class="n">on</span> <span class="n">bean</span> <span class="n">named</span> <span class="n">AsynchronousAccessBean</span> <span class="k">for</span> <span class="n">appname</span>  <span class="n">modulename</span> <span class="n">jboss</span><span class="o">-</span><span class="n">ejb</span><span class="o">-</span><span class="n">asynchronous</span><span class="o">-</span><span class="n">ejb</span> <span class="n">distinctname</span>  <span class="n">due</span> <span class="n">to</span><span class="o">:</span> <span class="n">java</span><span class="p">.</span><span class="n">io</span><span class="p">.</span><span class="n">IOException</span><span class="o">:</span> <span class="n">JBAS014560</span><span class="o">:</span> <span class="n">Could</span> <span class="n">not</span> <span class="n">open</span> <span class="n">message</span> <span class="n">outputstream</span> <span class="k">for</span> <span class="n">writing</span> <span class="n">to</span> <span class="n">Channel</span>
</pre></div>
<h2><a id="undeploy-the-archive" class="anchor" href="#undeploy-the-archive"><span class="anchor-icon"></span></a>Undeploy the Archive</h2>

<ol>
<li>Make sure you have started the JBoss Server as described above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>When you are finished testing, type this command to undeploy the archive:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="o">:</span><span class="n">undeploy</span>
</pre></div></li>
</ol>

<h2><a id="run-the-quickstart-in-jboss-developer-studio-or-eclipse" class="anchor" href="#run-the-quickstart-in-jboss-developer-studio-or-eclipse"><span class="anchor-icon"></span></a>Run the Quickstart in JBoss Developer Studio or Eclipse</h2>

<p>You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see <a href="../README.html#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts">Use JBoss Developer Studio or Eclipse to Run the Quickstarts</a> </p>

<h2><a id="debug-the-application" class="anchor" href="#debug-the-application"><span class="anchor-icon"></span></a>Debug the Application</h2>

<p>If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">dependency</span><span class="o">:</span><span class="n">sources</span>
<span class="n">mvn</span> <span class="n">dependency</span><span class="o">:</span><span class="n">resolve</span> <span class="o">-</span><span class="n">Dclassifier</span><span class="o">=</span><span class="n">javadoc</span>
</pre></div>
<hr/>
</body></html>
